<template>
  <div class="table">
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column prop="admin_account" label="账号" width="180"></el-table-column>
      <el-table-column prop="admin_name" label="姓名" width="180"></el-table-column>
      <el-table-column prop="admin_phone" label="邮箱"></el-table-column>
      <el-table-column prop="admin_password" label="密码"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button class="button" @click="editAccount(scope)">修改</el-button>
          <el-button class="button" @click="handleForbidden(scope)">{{scope.row.is_forbidden == 1 ? '禁用' : '启用'}}</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import {isForbidden} from '@/api/operation'
import {ERR_OK} from '@/api/config'
import {Message} from 'element-ui'
export default {
  props: {
    tableData: {
      type: Array,
      default: () => []
    }
  },
  methods: {
    editAccount(scope) {
      this.$router.push({path: `/account/accountlist/editAccount/${scope.row.id}`})
      localStorage.setItem('ACCOUNT_DETAIL', JSON.stringify(scope.row))
    },
    handleForbidden(scope) {
      
      let index = this.tableData.findIndex((item) => {
        return item.id == scope.row.id
      })
      
      this._isForbidden(scope.row.id, this.tableData[index].is_forbidden)

      if (index >= 0) {
        this.tableData[index].is_forbidden = this.tableData[index].is_forbidden == 1 ? 2 : 1
      }
      
      console.log(this.tableData[index].is_forbidden)
    },
    _isForbidden(admin_id, type) {
      isForbidden(admin_id, type)
        .then((res) => {
          if (res.code == ERR_OK) {
            // console.log(res)
            Message({
              message: res.message,
              type: 'info'
            })
          }
        })
        .catch((err) => {
          console.log(err)
        })
    }
  },
  data() {
    return {};
  }
};
</script>
<style lang="scss" scoped>
.el-table .warning-row {
  background: #ddd;
}

.el-table .success-row {
  background: #ddd;
}
.table {
  .el-table /deep/ .has-gutter {
    tr {
      th {
        text-align: center;
      }
    }
  }
  .el-table /deep/ .el-table__row {
    td {
      text-align: center;
    }
  }
  .el-table /deep/ .el-table__header-wrapper {
    border-bottom: 1px solid #EBEEF5;;
  }
  .button {
    width: 59px;
    height: 30px;
    line-height: 20px;
    border-radius: 6px;
    background-color: rgba(27, 166, 135, 1);
    text-align: center;
    padding: 0;
    color: #fff;
  }
}
</style>